package com.zmn.oms.zmn.business.impl.work.autoflow.state;

import com.zmn.oms.business.interfaces.work.tag.OrderTagBService;
import com.zmn.oms.common.constant.OrderStatusConsts;
import com.zmn.oms.common.dto.ResultDTO;
import com.zmn.oms.model.entity.work.OrderWork;
import com.zmn.oms.zmn.business.interfaces.work.ZsOrderWorkOperatePermissionBService;
import com.zmn.oms.zmn.business.interfaces.work.autoflow.state.WorkAutoFlowBService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * 类描述：标签
 *
 * @author wangxiaokun
 * @since 2022/07/28 15:02
 */
@Slf4j
@Service("flowTagBService")
public class FlowTagBServiceImpl<T> implements WorkAutoFlowBService<T> {

    @Autowired
    private ZsOrderWorkOperatePermissionBService zsOrderWorkOperatePermissionBService;
    @Autowired
    private OrderTagBService orderTagBService;

    @Override
    public ResultDTO<T> condition(OrderWork orderWork) {

        // 不是已录入不处理
        if (!Objects.equals(orderWork.getStatus(), OrderStatusConsts.WORK_STATUS_INPUT)) {
            return ResultDTO.fail("不是已录入不处理");
        }

        return ResultDTO.success(orderWork);
    }

    @Override
    public void execute(T t) {
        try {
            orderTagBService.autoAddOrderTag((OrderWork) t);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("自动流转加标签异常：[{}]", e.getMessage());
        }
    }
}
